package com.zhiyiang.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.zhiyiang.Vo.RoomVO;
import com.zhiyiang.mapper.RoomMapper;
import com.zhiyiang.pojo.Hotel;
import com.zhiyiang.pojo.Room;
import com.zhiyiang.service.room.RoomService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/room")
public class RoomController {
    @Autowired
    private RoomService roomService;
    @GetMapping(value = "/findAll/{current}/{size}")
    @ResponseBody
    public Page<RoomVO> doRoom(@PathVariable("current") Integer current, @PathVariable("size") Integer size){
        Page<RoomVO> allHotel = roomService.getAllHotel(current, size);
        return allHotel;
    }
    //查询当前登录酒店的所有房间
    @GetMapping("/getloginroom/{usercode}/{current}/{size}")
    public Page<RoomVO> getLoginRoom(@PathVariable("usercode") String usercode,
                                     @PathVariable("current") Integer current,
                                     @PathVariable("size") Integer size){
        Page<RoomVO> allroom = roomService.getLoginRoom(usercode,current,size);
        return allroom;
    }
    //根据房间号查询房间
    @GetMapping (value = "/findRoom/{usercode}/{query}/{current}/{size}")
    @ResponseBody
    public Page<RoomVO> doRoom(@PathVariable("usercode") String usercode,
                             @PathVariable("query") String query,
                             @PathVariable("current") Integer current,
                             @PathVariable("size") Integer size){
        Page<RoomVO> allroom = roomService.getRoom(usercode,query,current,size);
        return allroom;
    }

    //获取当前行酒店
    @GetMapping(value = "/getRoom/{id}")
    @ResponseBody
    public Room getRoom(@PathVariable("id") Integer id){
        Room room = roomService.getRoom(id);
        return room;
    }
    //添加房间
    @PostMapping (value = "/addRoom")
    @ResponseBody
    public Boolean doRoom(@RequestBody Room room){
        Boolean flag = roomService.addRoom(room);
        System.out.println(flag);
        return flag;
    }
    //更新房间
    @PutMapping(value = "updateRoom/{id}")
    @ResponseBody
    public Boolean updateHotel(@PathVariable("id") String id,
                               @RequestBody Room room){
        Boolean flag = roomService.updateRoom(id, room);
        return flag;
    }

    //删除当前行酒店
    @GetMapping(value = "/deleteRoom/{id}")
    @ResponseBody
    public Boolean deleteHotel(@PathVariable("id") String id){
        Boolean flag = roomService.deleteRoom(id);
        return flag;
    }
    //打扫房间
    @GetMapping("/updateState/{id}")
    public void updateState(@PathVariable("id") Integer id){
        roomService.updateState(id);
    }
    //获取可以预定的房间
    @GetMapping("getRooms/{orderhotel}/{roomtype}")
    public List<Room> getRooms(@PathVariable("orderhotel") Integer orderhotel,@PathVariable("roomtype") Integer roomtype){
        return roomService.getRooms(orderhotel,roomtype);
    }
    //预定修改状态
    @GetMapping("/reserveState/{roomcode}/{orderhotel}")
    public void reserveState(@PathVariable Integer roomcode,
                             @PathVariable Integer orderhotel){
        roomService.reseveState(roomcode,orderhotel);
    }
}
